<html>
	<head>
		<meta charset="utf-8">
		<title>表单</title>
		<script>
			// function checkForm() {
			// 	// body...
			// 	if (document.form1.username.value) {
			// 		var arr = ["#", "$", "%", "^", "&", "*", "[", "]", "{", "}"];
			// 		var str = document.form1.username.value
			// 		for (var i = 0; i < arr.length; i++) {
			// 			for (var j = 0; j < str.length; j++) {
			// 				if (arr[i] == str.charAt(j)) {
			// 					alert("用户名中含有特殊字符！！");
			// 					return false;
			// 				} 
			// 			}
			// 		}
			// 	} else {
			// 		alert("用户名不能为空！！");
			// 		return false;
			// 	}
			// }
			function checkForm1 () {
				$uname = document.form1.username.value;
				if ($uname.length == 0) {
					alert("用户名不能为空");
				} else if($uname.length < 5 || $uname.length > 20) {
					alert("用户名只能介于5-20个字符");
				} else if (getSpecialChar($uname)) {
					alert("验证通过！");
				} else {
					alert("用户名含有特殊字符！！");
				}
			}

			function getSpecialChar (str) {
				var arr = ["#", "$", "%", "^", "&", "*", "[", "]", "{", "}"];
				for (var i = 0; i < arr.length; i++) {
					for (var j = 0; j < str.length; j++) {
						if (arr[i] == str.charAt(j)) {
							return false
						} 
					}
				}
				return true;
			}
			document.onkeydown = echoWorder;
			function echoWorder() {
				alert("其实很想留，其实很想走。");
			}
		</script>
	</head>
	<body>
		<!-- <form action="Class1.html" onsubmit="return checkForm()" name="form1">
			用户名<input type="text" name="username">
			密码<input type="text" name="passwpd">
			<input type="submit" value="提交验证">
		</form> -->
		<form name="form1">
			用户名<input type="text" name="username">
			密码<input type="text" name="passwpd">
			<input type="submit" value="提交验证" onclick="checkForm1()">
		</form>
	</body>
</html>